package com.fairytask.engine.components
{
	import com.fairytask.engine.GameStage;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.define.Filter;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.engine.utils.IO;
	import com.fairytask.managers.ResManager;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.events.SecurityErrorEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFormat;

	/** 纯AS静态悬浮提示工具   			version 1.0
	 * 				(由于实时更换背景的可能性比较小，因此没有对加载进来的背景进行储存)
	 * 	@author hanjy				2010.11.05
	 *
	 * 			该工具类在一个swf播放器中始终只存在一个实例
	 *
	 *  通用设置（使用下面的设置的时候会改变全局的显示效果）
	 *
	 * 			作用							方法
	 * 		1.设置背景颜色				ToolTips.setBgColor		(新的十六进制颜色色值);
	 * 		2.设置边框线条颜色			ToolTips.setBorderColor	(新的十六进制颜色色值);
	 * 		3.设置文本颜色				ToolTips.setTextColor		(新的十六进制颜色色值);
	 * 		4.设置背景透明度				ToolTips.setBgAlpha		(新的透明度值);
	 * 		5.设置背景图片				ToolTips.setBgImageUrl		(背景地址);
	 * 		6.设置缩放区域				ToolTips.setBgScale9Grid	(缩放区域);  				（当背景设置正确后才能选择使用）
	 *
	 * 		finale 隐藏提示框			ToolTips.hide();
	 *
	 * 		*******   		注意 		********
	 * 			1.若中途需要修改以上的2个或2个以上的属性，建议直接重新初始化该类 即调用 ToolTips.Init(...argc)
	 * 			2.设置背景图片且成功加载后，自动绘制的背景颜色及线条将不存在.其他情况下，都会使用定义的配置颜色进行绘制背景
	 * 			3.更换或初次设置图片的时候，不会立即显示新的背景图片，当再次调用ToolTips.ShowInfo(...argc)的时候才会显示
	 * 		*******
	 *
	 *  使用方法有2种
	 *
	 * 	方法一使用步骤
	 * 		1.在主文档类中先初始化该类 即直接调用 		ToolTips.Init(...argc);
	 * 		2.在要显示悬浮提示的时候调用				ToolTips.ShowInfo(...argc);
	 *
	 *  方法二
	 * 		直接使用  ToolTips.ShowInfo(...argc) ，此方法下的悬浮框将使用默认的颜色配置
	 */
	public class ToolTips extends Sprite
	{
		private static var _stage				:Stage;
		private static var bgAlpha			:Number     =1; //背景透明度
		private static var bgColor			:uint       =0x000000; //背景颜色
		private static var bgImageData		:DisplayObject=null;
		private static var bgScale9Grid		:Rectangle  =null;
		private static var borderColor		:uint       =0xccff00; //线条颜色
		private static var hasConstruct		:Boolean    =false;
		private static var notePanel			:ToolTips;
		private static var textColor			:uint       =0xffff99; //0xf9f9f9;	//字体颜色
	    public static var starMc				:Sprite     =new Sprite();
		public static var starMcContrast		:Sprite		=new Sprite();
		public static var petTipsSP			:Sprite		=new Sprite();
		private var showEgg					:Boolean	=false;
		
		private var bg							:Sprite     =new Sprite;
		private var bgContrast					:Sprite		=new Sprite();
		private var dy							:int        =0;
		private var rate						:int        =5;
		private var container					:Sprite		=new Sprite();
		private var contastContainer			:Sprite		=new Sprite();	
		
		private var rx							:int        =0;
		private var txtContrast				:TextField  =new TextField();
		private var txtOriginal				:TextField  =new TextField();
		//判断是否需要对比装备
		
		private static var _clip				:Clip	=	new Clip();
		private static var _compareIcon		:Clip	=	new Clip(true);
		private static var _iconId			:int;
		//TIPS宽度
		private const	TIPS_WIDTH		:int	=	265;//tips宽度
		private const	PETEGG_WIDTH	:int	=	300;//tips宽度
		private const	TIPS_TXT_SPACE	:int 	=	25;//文本宽度离tips宽度距离
		public static const TxtStyleAuto				:int 	= 	0;//文本文字宽度不限制
		public static const TxtStyleFixed				:int 	= 	1;//文本宽度限制
		
		private static var _customFit	:Boolean	=	false;	//是否自适应
		private static var _hasIcon	:Boolean	=	false;	//是否带ICON
		private static var _isCompare	:Boolean	=	false;	//是否比较
		private	var _commonBg		:MovieClip	=	ResManager.newResClass("tips_bk") as MovieClip;
		private	var _compareBg		:MovieClip	=	ResManager.newResClass("tips_bk") as MovieClip;
		
		
		public function ToolTips()
		{
			if (ToolTips._stage || ToolTips.hasConstruct)
			{
				throw new Error(" ------- ToolTips 已经在内存中存在，不能重复构建 ToolTips -------");
				return;
			}
			
			ToolTips.hasConstruct=true;
			this.mouseChildren=false;
			this.mouseEnabled=false;
			this.visible=false;
			this.addEventListener(Event.ADDED_TO_STAGE, init);
			this.addEventListener(Event.REMOVED_FROM_STAGE, deleteEvent);
		}

		/** 将目标绑定鼠标滑过和离开的事件显示信息(适用于提示信息固定不变的)
		 *
		 * @param target				包绑定的对象
		 * @param content				要显示的提示信息
		 *
		 */
		public static function BindTip(target:DisplayObject, content:String,txtStyle:int=TxtStyleAuto):void
		{
			var onover:Function    =function(e1:MouseEvent):void
			{
				ToolTips.ShowInfo(content,txtStyle,-1,true);
			}

			var onout:Function     =function(e2:MouseEvent):void
			{
				ToolTips.hide();
			}

			var removeBind:Function=function(e3:Event):void
			{
				e3.currentTarget.removeEventListener(MouseEvent.ROLL_OVER, onover);
				e3.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, onover);
				e3.currentTarget.removeEventListener(MouseEvent.ROLL_OUT, onout);
				e3.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, onout);
				e3.currentTarget.removeEventListener(Event.REMOVED_FROM_STAGE, removeBind);
				onover=null;
				onout=null;
				removeBind=null;
				ToolTips.hide(true);
			}

			target.addEventListener(MouseEvent.ROLL_OVER, onover);
			target.addEventListener(MouseEvent.MOUSE_OVER, onover);
			target.addEventListener(MouseEvent.ROLL_OUT, onout);
			target.addEventListener(MouseEvent.MOUSE_OUT, onout);
//			target.addEventListener(Event.REMOVED_FROM_STAGE, removeBind);
		}

		/** 初始化基本设置，一般在主类最前面使用
		 *
		 * @param _client			显示对象的载体
		 * @param _bgColor			背景颜色
		 * @param _borderColor		边框线条颜色
		 *
		 * @param _bgImageUrl		背景图片地址（可以是swf）,如果不设置，则背景为纯色绘制底图
		 * @param _bgScale9Grid		如果设置了正确的背景地址（能正确访问到的图片或者swf地址），
		 * 							那么在背景加载完成后，则自动按这个rectangle配置缩放区域，不设置值的时候将按默认的值进行缩放
		 * 							默认值为大小是 50*20 的源文件，缩放区域是 (5,5,40,10);
		 * @param _textColor		文字颜色
		 * @param _bgAlpha			透明度
		 *
		 */
//		public static function Init(_client:DisplayObject, _bgColor:uint=0x000000, _borderColor:uint=0xccff00, _bgImageUrl:String=null, _bgScale9Grid:Rectangle=null, _textColor:uint=0xf9f9f9, _bgAlpha:Number=1,_starVis:Boolean=false):void
		public static function Init(_client:DisplayObject, backGround:DisplayObject, _textColor:uint=0xf9f9f9, _bgAlpha:Number=1,_starVis:Boolean=false):void
		{
//			ToolTips.setBgColor(_bgColor);
//			ToolTips.setBorderColor(_borderColor);
			ToolTips.bgImageData	=	backGround;
			ToolTips.setTextColor(_textColor);
//			ToolTips.setBgAlpha(_bgAlpha);
//			ToolTips.setBgImageUrl(_bgImageUrl);
//			ToolTips.setBgScale9Grid(_bgScale9Grid);
			
			if (!ToolTips._stage)
			{
				if (_client.stage)
				{
					ToolTips.notePanel=new ToolTips();
					ToolTips.notePanel.constructBitmapBg();
					ToolTips._stage=_client.stage;
					ToolTips._stage.addChild(ToolTips.notePanel);
				}
				else
				{
					throw new Error("初始化失败, " + _client + " 不在显示列表中，请先将 " + _client + " 添加到显示列表中!");
				}
			}
		}

		/** 静态方法 显示提示信息
		 *
		 * @param content			信息内容
		 * @param followMouse		是否跟随鼠标，如果不跟随鼠标，则必须设置stagePosition参数
		 * @param stagePosition		全局（舞台）坐标点  (此参数只在followMouse设置为false的时候才有效)
		 * 
		 */
		
		public static function ShowInfo(content:String,txtStyle:int,iconId:int=-1,customFit:Boolean=false,followMouse:Boolean=true, stagePosition:Point=null):void
		{

			if (!ToolTips._stage)
			{
//				IO.traceLog("    提示信息:", content);
//				IO.traceLog("还没对 ToolTips 进行初始化，请先调用 ToolTips.Init(...argc) 对ToolTips进行初始化");
				return;
			}

			if (!content || 1 > content.length)
			{
				return;
			}
			ToolTips.hide();
			/*while(starMc.numChildren>0)
			{
				starMc.removeChildAt(0);
			}*/
			_customFit	=	customFit;
			
			if(-1	!=	iconId)
			{
				_iconId		=	iconId;
				_hasIcon	=	true;								
			}

			ToolTips.notePanel.showText(content, followMouse, stagePosition,false,txtStyle);
		}
		
		/**
		 * 显示宠物蛋tips 
		 * @param configID
		 * @param data
		 * @param iconId
		 * @param customFit
		 * @param followMouse
		 * @param stagePosition
		 * 
		 */
		public static function ShowEggInfo(sp:Sprite,iconId:int=-1,customFit:Boolean=false,followMouse:Boolean=true, stagePosition:Point=null):void
		{
			if (!ToolTips._stage)
			{
				return;
			}
			ToolTips.hide();
			_customFit	=	customFit;
			
			if(-1	!=	iconId)
			{
				_iconId		=	iconId;
				_hasIcon	=	true;								
			}
			ToolTips.notePanel.showBG(sp,followMouse, stagePosition);
		}
		
		public final function showBG(sp:Sprite, followMouse:Boolean=true, stagePosition:Point=null):void
		{
			sp.x = 5;
			sp.y = 10;
			ToolTips.petTipsSP.addChild(sp);
			showEgg = true;
			if (!ToolTips.bgImageData)
			{
				//如果背景图片没有加载完成或者没设置背景图片，则自动填充先前设置过的背景颜色
				this.drawBg();
			}
			else
			{
				//绘制TIPS背景
				this.constructBitmapBg();
			}
			this.bg.alpha=ToolTips.bgAlpha;
			
			this.visible=true;
			
			this.removeEventListener(Event.ENTER_FRAME, onTipsMove);
			
			if (followMouse)
			{
				this.addEventListener(Event.ENTER_FRAME, onTipsMove);
			}
			else
			{
				//TIP正常状态，没有设置固定值
				if (!stagePosition)
				{
					this.x=(_stage.stageWidth - this.width) / 2;
					this.y=(_stage.stageHeight - this.height) / 2;
				}
				else
				{
					//超边界处理
					this.x=stagePosition.x;
					if((_stage.stageWidth-stagePosition.x)<this.width)
					{
						this.x	=	stagePosition.x	-this.width-15;
					}
					
					this.y=stagePosition.y;
					if(_stage.stageHeight-stagePosition.y<this.height)
					{
						this.y	=	_stage.stageHeight		-	this.height;
					}
				}
				this.alpha=1;
				this.visible=true;
			}
			this.parent.setChildIndex(this, this.parent.numChildren - 1);
		}
		
		/**
		 *	比较TIPS 
		 * @param content
		 * 
		 */		
		private static var _compareId		:int	=	-1;
		public static function ShowContrastInfo(content:String,compareId:int,txtStyle:int=TxtStyleAuto):void
		{
			_compareId	=	compareId;
			ToolTips.notePanel.showContrastText(content,txtStyle);
		}
		
		/**
		 *添加装备星级 
		 * 
		 */		
//		public static var stMc	:Sprite;
		public static function addStar(maxStar:int=0,star:int=0,starContrast:Boolean=true):void
		{
			var stMc:Sprite;
			if(starContrast)
			{
				stMc=starMc;
			}
			else
			{
				//人物装备的
				stMc=starMcContrast;
			}
			while(stMc.numChildren>0)
			{
				stMc.removeChildAt(0);
			}
			
			var i:int=0
			for(i;i<maxStar;i++)
			{
				var sMc  :MovieClip=ResManager.newResClass("CheckBoxSkin_211") as MovieClip;
				if(i>8)
				{
					sMc.x=(i-9)*23;
					if(_isCompare)
					{
						sMc.y=75;
					}
					else
					{
						sMc.y=60;
					}
				}
				else
				{
					sMc.x=i*23;
					if(_isCompare)
					{
						sMc.y=53;
					}
					else
					{
						sMc.y=38;
					}
				}
				if(i>=star)
				{
					sMc.gotoAndStop(2);
				}
				else
				{
					sMc.gotoAndStop(1);
				}
				stMc.addChild(sMc);
			}
		}
		

		/** 
		 * 移动提示框的位置
		 * @param X
		 * @param Y
		 *
		 */
		public static function moveTo(X:Number, Y:Number):void
		{
			if (notePanel)
			{
				notePanel.x=X;
				notePanel.y=Y;
			}
		}

		/**
		 *	隐藏TIPS 
		 * 
		 */		
		
		private function emptyContrast():void
		{
			while(starMcContrast.numChildren>0)
			{
				starMcContrast.removeChildAt(0);
			}
			
			txtContrast.width	=	0;
			txtContrast.htmlText	=	"";
			txtOriginal.htmlText	=	"";
			showEgg = false;
		}
		
		public final function hideText():void
		{
			this.removeEventListener(Event.ENTER_FRAME, onTipsMove);
			this.visible	=	false;
			contastContainer.visible	=	false;
			emptyContrast();
			
			return;

			if (this.visible)
			{
				this.addEventListener(Event.ENTER_FRAME, effOut);
			}
		}
		
		private function effOut():void
		{
			
		}

		/** 实例显示提示信息的接口
		 *
		 * @param content			信息内容
		 * @param followMouse		是否跟随鼠标，如果不跟随鼠标，则必须设置stagePosition参数
		 * @param stagePosition		全局（舞台）坐标点  (此参数只在followMouse设置为false的时候才有效)
		 *
		 */
		public final function showText(str:String, followMouse:Boolean=true, stagePosition:Point=null,starBool:Boolean=false,txtStyle:int=TxtStyleAuto):void
		{
			//设置TIPS文本
			this.printText(txtOriginal,str,txtStyle);
			if (!ToolTips.bgImageData)
			{
				 //如果背景图片没有加载完成或者没设置背景图片，则自动填充先前设置过的背景颜色
				this.drawBg();
			}
			else
			{
				//绘制TIPS背景
				this.constructBitmapBg();
			}
			this.bg.alpha=ToolTips.bgAlpha;

			this.visible=true;

			this.removeEventListener(Event.ENTER_FRAME, onTipsMove);

			if (followMouse)
			{
				this.addEventListener(Event.ENTER_FRAME, onTipsMove);
			}
			else
			{
				//TIP正常状态，没有设置固定值
				if (!stagePosition)
				{
					this.x=(_stage.stageWidth - this.width) / 2;
					this.y=(_stage.stageHeight - this.height) / 2;
				}
				else
				{
					//超边界处理
					this.x=stagePosition.x;
					if((_stage.stageWidth-stagePosition.x)<this.width)
					{
						this.x	=	stagePosition.x	-this.width-15;
					}
					
					this.y=stagePosition.y;
					if(_stage.stageHeight-stagePosition.y<this.height)
					{
						this.y	=	_stage.stageHeight		-	this.height;
					}
				}
				this.alpha=1;
				this.visible=true;
			}
			this.parent.setChildIndex(this, this.parent.numChildren - 1);
		}

		
		/**
		 * TIPS文字显示初始化  
		 * @param text
		 * @param str
		 * @param type 文字显示方式:0自动 1固定
		 * 
		 */		
		private final function printText(text:TextField,str:String,type:int):void
		{
			text.filters	=	[Filter.INNER_TEXT_FILTER];
			text.width=350;
			text.height=200;
			text.htmlText=str;
			if(type == TxtStyleAuto)
			{
				text.width= text.textWidth + 6;
			}
			else if(type == TxtStyleFixed)
			{
				text.width = TIPS_WIDTH - TIPS_TXT_SPACE;
			}
			
			if (text.bottomScrollV > 1)
			{
				text.height=text.textHeight + 6;
			}
			else
			{
				text.height=text.textHeight + 4;
			}
			text.x=5;
			text.y=2;
			
		}
		
		/**
		 *	显示比较Tips 
		 * @param str
		 * 
		 */		
		public final function showContrastText(str:String,txtStyle:int=TxtStyleAuto):void
		{
			_isCompare	=	true;
			//TODO
			txtContrast.width	=	150
			contastContainer.visible	=	true
			this.printText(txtContrast,str,txtStyle);
			
			if (!ToolTips.bgImageData)
			{
				//绘制背景
				this.drawBg();
			}
			else
			{
				//自定义背景
				this.constructBitmapBg();
			}
			this.bgContrast.alpha=ToolTips.bgAlpha;
		}
		
		/**
		 *	清空常规TIPS 
		 * 
		 */		
		private function cleanBg():void
		{
			while (bg.numChildren>0)
			{
				bg.removeChildAt(0);
			}
		}
		/**
		 *	清空比较TIPS 
		 * 
		 */		
		private function cleanContrast():void
		{
			while(bgContrast.numChildren>0)
			{
				bgContrast.removeChildAt(0);
			}
		}
		
		/**
		 *	绘制TIPS 背景 
		 * 
		 */		
		private final function constructBitmapBg():void
		{
			if (!bgImageData)
			{
				return;
			}
//			if (!(bgImageData is Bitmap))
//			{
//				
//				ToolTips.bgImageData.width=this.txtOriginal.width + 8;
//				ToolTips.bgImageData.height=this.txtOriginal.height + 3;
//				bg.addChild(ToolTips.bgImageData);
//				return;
//			}
			cleanContrast();
			cleanBg();
			//this.bg.addChild(BitmapAPI.scaleBitmap(bgImageData as Bitmap,TIPS_WIDTH,txtOriginal.height+3,ToolTips.bgScale9Grid));
			
			var tmpHeight	:Number	=	txtOriginal.height+3;
			var tmpWidth	:Number	=	TIPS_WIDTH;

			//自适应TIPS
			if(_customFit)
			{
				tmpWidth	=	txtOriginal.width+8;
				tmpHeight	=	txtOriginal.height+3;
				while(container.numChildren > 2)
				{
					container.removeChildAt(container.numChildren-1);	
				}
			}
			
			//如果有图标
			if(_hasIcon)
			{
				_commonBg.x	= 203
				_commonBg.y	=	5;
				_clip.x =	_commonBg.x + 2;
				_clip.y =	_commonBg.y + 2;
				container.addChild(_commonBg);
				
				_clip.source	=	ResConfig.iconPath+_iconId+ResConfig.iconImg;
				tmpWidth	=	TIPS_WIDTH;
				tmpHeight	=	txtOriginal.height+3;
				container.addChild(_clip);
			}else
			{
				if(_commonBg.parent)
				{
					_commonBg.parent.removeChild(_commonBg);
				}	
				if(_clip.parent)
				{
					_clip.parent.removeChild(_clip);
				}
			}
			
			if(showEgg)
			{
				tmpWidth	=	PETEGG_WIDTH;
				tmpHeight	=	petTipsSP.height + 10;
				_commonBg.x	= _clip.x =	253;
			}
			if(_isCompare)
			{
				var tmpBitMap	:DisplayObject	=	ResManager.newResClass("tips_bk");
				tmpBitMap.width		=tmpWidth;	
				tmpBitMap.height	=txtContrast.height+3;
				
				_compareIcon.source	=	ResConfig.iconPath+_compareId+ResConfig.iconImg;
				
				bgContrast.addChild(tmpBitMap);//BitmapAPI.scaleBitmap(bgImageData as Bitmap,tmpWidth,tmpHeight,new Rectangle(5, 5, 40, 10)));
			}
			bgImageData.width	=	tmpWidth;
			bgImageData.height	=	tmpHeight;
			bg.addChild(bgImageData);
		}
		
		private final function drawBg():void
		{
			this.bg.graphics.clear();
			this.bg.graphics.lineStyle(1.1, borderColor, 0.6);
			this.bg.graphics.beginFill(bgColor);
			if(this.txtOriginal.width<starMc.width)
			{
				this.bg.graphics.drawRoundRect(0, 0, starMc.width + 5.5, this.txtOriginal.height + 2.5, this.rate, this.rate);
			}
			else
			{
				this.bg.graphics.drawRoundRect(0, 0, this.txtOriginal.width + 5.5, this.txtOriginal.height + 2.5, this.rate, this.rate);
			}
			this.bg.graphics.endFill();
		}
		

		private final function deleteEvent(e:Event):void
		{
			ToolTips._stage=null;
			ToolTips.hasConstruct=false;
			ToolTips.bgImageData=null;
			ToolTips.bgScale9Grid=null;
			this.removeEventListener(Event.ENTER_FRAME, onTipsMove);
		}


		/**
		 *	鼠标跟随 
		 * @param e
		 * 
		 */		
		private final function onTipsMove(e:Event):void
		{

			//Tips当前位置
			this.x=this.stage.mouseX + 12;
			this.y=this.stage.mouseY + 12;
			//超出舞台边界重置TIP位置
			var toRightSpace	:int	=	int(this.stage.stageWidth-(this.x+this.width));
			var toBottomSpace	:int	=	int(this.stage.stageHeight-(this.y+this.height));

			if(false	==	_isCompare)
			{
				if(toRightSpace<0)
				{
					this.x	=	this.stage.mouseX	-	container.width	-12;				
				}
				if(toBottomSpace<0)
				{
					this.y	=	this.stage.mouseY	-	container.height -12;	
				}
				
				if(this.y<0)
				{
					this.y=GameStage.stage.stageHeight	-	this.height;
				}
				if(this.x<0)
				{
					this.x	=	0;					
				}
			}
			else
			{
				//有比较TIPS时
				contastContainer.x	=	container.width	+	5;
				if(toRightSpace<0)
				{
					this.x	=	this.stage.mouseX	-	(container.width+contastContainer.width+12);				
				}
				
				if(toBottomSpace<0)
				{
					this.y	=	this.stage.mouseY	-	(container.height>contastContainer.height?container.height:contastContainer.height+12);								
				}
				
				if(this.y<0)
				{
					this.y=GameStage.stage.stageHeight	-	this.height;
				}
				if(this.x<0)
				{
					this.x	=	0;					
				}
			}
		}

		/** 重绘基本界面
		 *
		 * @param argc			参数暂时不处理
		 *
		 */

		private final function init(... argc):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, init);
			_commonBg.width	=	54;
			_commonBg.height	=	54;
			_compareBg.width	=	54;
			_compareBg.height	=	54;
			
			_clip.x	=	205;
			_clip.y	=	6;
			addChild(container);
			container.addChild(bg);
			starMc.x=8;
			container.addChild(starMc);
			container.addChild(petTipsSP);

			var format:TextFormat=new TextFormat();
			format.leftMargin=0;
			format.rightMargin=0;
			format.color=textColor;
			format.size=12;
			format.font="Arial";
			format.leading=1;

			this.txtContrast.y	=	15;
			this.txtOriginal.width=150;
			this.txtOriginal.height=0;
			this.txtOriginal.multiline=true;
			this.txtOriginal.wordWrap=true;
			this.txtOriginal.selectable=false;
			this.txtOriginal.defaultTextFormat=format;
			this.txtOriginal.filters=[new ColorMatrixFilter()];
			this.addChild(this.txtOriginal);
			this.addChild(petTipsSP);
			
			this.txtContrast.y	=	15;
			this.txtContrast.width=150;
			this.txtContrast.height=0;
			this.txtContrast.multiline=true;
			this.txtContrast.wordWrap=true;
			this.txtContrast.selectable=false;
			this.txtContrast.defaultTextFormat=format;
			this.txtContrast.filters=[new ColorMatrixFilter()];
			
			//比较TIPS
			starMcContrast.x=8;
			
			_compareBg.x	=	205;
			_compareBg.y	=	6;
			_compareIcon.x	=	_compareBg.x + 3;
			_compareIcon.y	=	_compareBg.y + 3;
			
			contastContainer.addChild(bgContrast);
			contastContainer.addChild(txtContrast);
			contastContainer.addChild(_compareBg);
			contastContainer.addChild(_compareIcon);
			contastContainer.addChild(starMcContrast);
			contastContainer.visible=false;
			addChild(contastContainer);
		}
		

		
		/** 获取当前提示框的高度
		 *
		 * @return
		 *
		 */
		public static function getHeight():Number
		{
			if (notePanel)
			{
				return notePanel.height;
			}
			return 0;
		}
		
		/** 获取当前提示框的宽度
		 *
		 * @return
		 *
		 */
		public static function getWidth():Number
		{
			if (notePanel)
			{
				return notePanel.width;
			}
			return 0;
		}
		
		/** 隐藏 ToolTips **/
		public static function hide(... rest):void
		{
			while(ToolTips.setObj.numChildren)
			{
				ToolTips.setObj.removeChild(ToolTips.setObj.getChildAt(0));
			}
			while(ToolTips.tipsSP.numChildren>0)
			{
				ToolTips.tipsSP.removeChild(ToolTips.tipsSP.getChildAt(0));
			}
			if (ToolTips.notePanel)
			{
				ToolTips.notePanel.hideText();
			}
			_clip.clear();
			_compareIcon.clear();
			_customFit	=	false;
			_hasIcon	=	false;
			_isCompare	=	false;
			_compareId	=	-1;
			_iconId	=	-1;
		}
		

		/** 设置背景透明度
		 *
		 * @param c				新的十六进制颜色色值
		 *
		 */
		public static function setBgAlpha(c:Number):void
		{
			c=Math.abs(c);
			if (c > 1)
			{
				c=(c % 101) / 100;
			}
			ToolTips.bgAlpha=c;
		}
		
		/** 设置提示框背景的颜色
		 *
		 * @param c				新的十六进制颜色色值
		 *
		 */
		public static function setBgColor(c:uint):void
		{
			ToolTips.bgColor=c;
		}
		
		/** 设置背景图片
		 *
		 * @param url			背景图片的路径，最好是绝对路径，默认图片大小为50*20，默认缩放区域为(5,5,40,10)便于拉伸
		 *
		 */
		public static function setBgImageUrl(url:String):void
		{
			if (!url)
			{
				return;
			}
			ToolTips.bgImageData=null;
			var ld:Loader=new Loader();
			ld.contentLoaderInfo.addEventListener(Event.COMPLETE, loadBgComplete);
			ld.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
			ld.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadError);
			ld.load(new URLRequest(url));
		}
		
		/** 设置背景缩放区域
		 *
		 * @param _bgScale9Grid			背景的缩放区域，默认图片大小为50*20，默认缩放区域为(5,5,40,10)便于拉伸
		 *
		 */
		public static function setBgScale9Grid(_bgScale9Grid:Rectangle):void
		{
			if (!_bgScale9Grid)
			{
				//建立9切片区域
				ToolTips.bgScale9Grid=new Rectangle(25, 25, 139, 142);
			}
			else
			{
				ToolTips.bgScale9Grid=_bgScale9Grid;
			}
		}
		
		/** 设置边框线条颜色
		 *
		 * @param c				新的十六进制颜色色值
		 *
		 */
		public static function setBorderColor(c:uint):void
		{
			ToolTips.borderColor=c;
		}
		/** 设置文本的颜色
		 *
		 * @param c				新的十六进制颜色色值
		 *
		 */
		public static function setTextColor(c:uint):void
		{
			ToolTips.textColor=c;
		}
		
		/**
		 *	TIPS 背景加载完毕 
		 * @param e
		 * 
		 */		
		private static function loadBgComplete(evt:Event):void
		{
			ToolTips.bgImageData=evt.target.content;
			if (ToolTips.bgImageData is Bitmap)
			{
				//				IO.traceLog('   ',ToolTips,'设置使用 位图 背景');
			}
			else
			{
				ToolTips.bgImageData.scale9Grid=ToolTips.bgScale9Grid;
			}
			
			if (ToolTips.notePanel)
			{
				ToolTips.notePanel.constructBitmapBg();
			}
		}
		
		private static function loadError(e:Event):void
		{
			IO.traceLog('    加载背景失败');
		}

		public static function get setObj():Sprite
		{
			return starMc;
		}
		
		public static function get tipsSP():Sprite
		{
			return petTipsSP;
		}
	}
}